package com.zy.service.bs.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zy.dao.bs.SuggestionDao;
import com.zy.entity.enums.StatusEnum;
import com.zy.entity.bs.Suggestion;
import com.zy.pojo.query.bs.SuggestionQuery;
import com.zy.pojo.vos.common.PageVo;
import com.zy.service.base.impl.BaseServiceImpl;
import com.zy.service.bs.SuggestionService;
import com.zy.utils.DateUtil;

@Service("suggestionService")
public class SuggestionServiceImpl extends BaseServiceImpl<Suggestion> implements SuggestionService {

	@Autowired
	private SuggestionDao suggestionDao;

	@Override
	public PageVo pageSuggestion(SuggestionQuery suggestionQuery, Integer start, Integer limit) {
		return new PageVo(start, limit, this.suggestionDao.countSuggestion(suggestionQuery), this.suggestionDao.listSuggestion(suggestionQuery, start, limit));
	}

	@Override
	public void saveSuggestion(Suggestion suggestion) {
		long time = DateUtil.getTime();
		this.suggestionDao.save(suggestion);
	}
	
	@Override
	public void updateSuggestion(Suggestion suggestion) {
		this.suggestionDao.updateByPrimaryKeySelective(suggestion);
	}

	@Override
	public void removeSuggestion(long id) {
		try {
			this.suggestionDao.removeByPrimaryKey(id);
		} catch (Exception e) {
			log.info(e.getMessage(),e);
			Suggestion suggestion = new Suggestion();
			suggestion.setId(id);
			this.suggestionDao.updateByPrimaryKeySelective(suggestion);
		}
	}

	@Override
	public void recover(long id) {
		Suggestion suggestion = new Suggestion();
		suggestion.setId(id);
		this.suggestionDao.updateByPrimaryKeySelective(suggestion);
	}

}
